package health.lm.com.shop.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.lm.sjy.titlebar.widget.CommonTitleBar;
import com.vondear.rxtool.RxSPTool;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import health.lm.com.component_base.base.mvp.activity.XActivity;
import health.lm.com.data.AppModel;
import health.lm.com.network.callback.SimpleCallBack;
import health.lm.com.router.ARouterConstant;
import health.lm.com.shop.R;
import health.lm.com.shop.R2;
import health.lm.com.shop.adapter.OrganizationAdapter;
import health.lm.com.shop.entity.OrganizationEntity;
import health.lm.com.shop.model.MallModel;

/**
 * Created by Android Studio .
 * Project：hlian health.lm.com.shop.activity
 * Date：2019/8/29 10:26
 * Introduce：组织结构图页面
 */
@Route(path = ARouterConstant.OrganizationChartActivity)
public class OrganizationChartActivity extends XActivity {
    @Autowired
    public String id;
    @BindView(R2.id.titlebar)
    CommonTitleBar mTitlebar;
    @BindView(R2.id.rv_list)
    RecyclerView mRvList;
    @BindView(R2.id.tv_title)
    TextView mTvTitle;
    @BindView(R2.id.linearLayout5)
    LinearLayout mLinearLayout5;
    private OrganizationAdapter mOrganizationAdapter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_organization_chart;
    }

    @Override
    public Object newP() {
        return null;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        mTitlebar.setListener((v, action, extra) -> finish());
        mTvTitle.setText("组织结构图");

        mRvList.setLayoutManager(new LinearLayoutManager(context));
        mOrganizationAdapter = new OrganizationAdapter(new ArrayList<>());
        mOrganizationAdapter.openLoadAnimation();
        mRvList.setAdapter(mOrganizationAdapter);

        getData();
    }

    private void setNewData(List<OrganizationEntity> pNewData) {
        mOrganizationAdapter.setNewData(pNewData);
    }

    private void getData() {
        if (TextUtils.isEmpty(id)) {
            id = RxSPTool.getString(context, AppModel.my_business_id);
        }
        MallModel.getInstance().getOrganizationData(id, new SimpleCallBack<List<OrganizationEntity>>() {
            @Override
            public void onSuccess(List<OrganizationEntity> pOrganizationEntities) {
                setNewData(pOrganizationEntities);
            }
        });
        //List<OrganizationEntity> list = new ArrayList<>();
        //for (int a = 0; a < 8; a++) {
        //    list.add(new OrganizationEntity("部门" + a, a + ""));
        //}
        //setNewData(list);
    }
}
